<!DOCTYPE html . "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
	<title></title>
	<!--载入编辑器-->
	<script type="text/javascript" charset="utf-8" src="Public/Admin/ueditor1_4_3/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="Public/Admin/ueditor1_4_3/ueditor.all.min.js"> </script>
    <script type="text/javascript" charset="utf-8" src="Public/Admin/ueditor1_4_3/lang/zh-cn/zh-cn.js"></script>
	<!--载入uploadify相关文件-->
	<script type="text/javascript" src="Public/Admin/uploadify/jquery-1.8.2.min.js"></script>
	<script type="text/javascript" src="Public/Admin/uploadify/jquery.uploadify.min.js"></script>
	<link href="Public/Admin/uploadify/uploadify.css" type="text/css" rel="stylesheet"></link>
	<!--载入hdjs-->
	<link rel="stylesheet" type="text/css" href="Public/Admin/hdjs/hdjs.css"/>
    <script src="Public/Admin/hdjs/hdjs.min.js" type="text/javascript" charset="utf-8"></script>
    <style type="text/css">
		li{
			list-style: none;
			float: right;
		}
		tr{
			height: 30px;
		}
		input{
			height: 20px;
			font-size: 14px;
		}
	</style>
</head>
<body>
	
	<div class="container-fluid">
	<div class="row-fluid">
	<div class="span12">
	<form action="" method='post' enctype="multipart/form-data" id="add_goods">			
			<h2 class="hd-title-header">添加商品</h2>
			<table class='hd-table hd-table-form' style="border-top:1px solid #E5E5E5 ;">	
			<p class="hd-title-header">基本信息</p>			

				<tbody>
					<tr class="info">
						<td>所属分类</td>
						<td>
							<select name="ygshop_category_cid">
								<option value="0">-请选择-</option>
									<?php foreach ($cateData as $v){?>
									<option value="<?php echo $v['cid']?>" tid="<?php echo $v['ygshop_type_tid']?>"/><?php echo $v['_name']?></option>
									<?php }?>

							</select>
						</td>
					</tr>
					<script type="text/javascript">
						$(function(){
							$("select[name=ygshop_category_cid]").change(function(){
								//获取当前选择的类型idq
								var tid = $(":selected").attr('tid');
								$('#tid').html('<input type="hidden" name="ygshop_type_tid" id="" value="<?php echo $v['ygshop_type_tid']?>" />');
								
								$.ajax({
									type:"post",
									url:"<?php echo U('ajaxGetAttr')?>",
									data:{tid:tid},
									dataType:"json",
									success:function(data){
										var attr = "";
										var spec = "";
										$.each(data, function(k,v) {
											if(v.class==1){
												attr += '<tr><td>'+v.taname+'</td><td><select name="attr['+v.taid+']"><option value="0">请选择</option>';
												$.each(v.taname,function(kk,vv){
								attr += 	'<option value="'+vv+'">'+vv+'</option>'; 				
												});
												attr += '</select></td></tr>';
											}else{
												spec += '<tr><td>'+v.taname+'</td><td><select name="spec['+v.taid+'][color][]"><option value="">请选择</option>';
																			$.each(v.tavalue,function(kk,vv){
													spec +='<option value="'+vv+'">'+vv+'</option>';
												})
												spec += '</select></td><td>附加价格</td><td>';
												spec += '<input type="text" name="spec['+v.taid+'][added][]" id="" value="0" />';
												spec += '</td><td><a href="javascript:;" class="hd-btn hd-btn-success hd-btn-sm addSpec">增加</a></td></tr>';
											}
										});
										$("#attr").html(attr);
										$('#spec').html(spec);
										
									}
								});
								
							})
						})
					</script>
					<!--点击增加按钮-->
					<script type="text/javascript">
						$(function(){
							$('.addSpec').live('click',function(){
								var tr = $(this).parents("tr").clone();
								var del = '<a href="javascript:;" class="hd-btn hd-btn-danger hd-btn-sm delSpec">删除</a>';
								tr.find(".addSpec").remove();
								tr.find("td").eq(4).append(del);
								$(this).parents("tr").after(tr);
							})
						})
					</script>
					<!--点击删除-->
					<script type="text/javascript">
						$(function(){
							$('.delSpec').live('click',function(){
								$(this).parents("tr").remove();
							})
						})
					</script>
					<tr class="info">
						<td>所属品牌</td>
						<td>
							<select name="ygshop_brand_bid">
								<option value="0">-请选择-</option>
									<?php foreach ($brandData as $v){?>
									<option value="<?php echo $v['bid']?>"><?php echo $v['bname']?></option>
									<?php }?>

						</td>
					</tr>
					<tr class="info">
						<td>商品名称</td>
						<td>
							<input type="text" name='gname' style="width: 400px;"/>
						</td>
					</tr>
					<tr class="info">
						<td>商品货号</td>
						<td>
							<input type="text" name='gnumber'/>
						</td>
					</tr>
					<tr class="info">
						<td>单位</td>
						<td>
							<input type="text" name='unit' value='件'/>
						</td>
					</tr>
					<tr class="info">
						<td>市价场</td>
						<td>
							<input type="text" name='marketprice'/>
						</td>
					</tr>
					<tr class="info">
						<td>商城价</td>
						<td>
							<input type="text" name='shopprice'/>
						</td>
					</tr>
					<tr class="info">
						<td>点击次数</td>
						<td>
							<input type="text" name='gclick'/>
						</td>
					</tr>
					<tr class="info">
						<td>库存</td>
						<td>
							<input type="text" name='gtotal'/>
						</td>
					</tr>
				</tbody>
			</table>

			<p class="hd-title-header">商品属性</p>
			<table class="hd-table hd-table-form" id='attr' style="border-top:1px solid #E5E5E5 ;">
				
			</table>
			<p class="hd-title-header">商品规格</p>
			<table class="hd-table hd-table-form" id='spec' style="border-top:1px solid #E5E5E5 ;">
				
			</table>
			
			<p class="hd-title-header">列表图</p>
			<table class='hd-table hd-table-form' style="border-top:1px solid #E5E5E5 ;">
			<tr class="info">
					<td>上传图片</td>
					<td>
						<input id="file1" type="file" multiple="true" name="pic"/>
	            		 <span>类型: *.jpg,*.png 大小: 2000KB 数量: 10</span>
			             <script type="text/javascript">
			                $(function() {
			                    $('#file1').uploadify({
			                        'formData'     : {//POST数据
			                            '<?php echo session_name();?>' : '<?php echo session_id();?>',
			                        },
			                        'fileTypeDesc' : '上传文件',//上传描述
			                        'fileTypeExts' : '*.jpg;*.png',
			                        'swf'      : 'Public/Admin/uploadify/uploadify.swf',
			                        'uploader' : "<?php echo U('ajaxUpload')?>",
			                        'buttonText':'选择文件',
			                        'fileSizeLimit' : '2000KB',
			                        'uploadLimit' : 1000,//上传文件数
			                        'width':65,
			                        'height':25,
			                        'successTimeout':10,//等待服务器响应时间
			                        'removeTimeout' : 0.2,//成功显示时间
			                        'onUploadSuccess' : function(file, data, response) {
			                            data=$.parseJSON(data);
			                            var imageUrl = data.image?data.url:'<?php echo __PUBLIC__?>/image/default.png';
										var li = '<li url="'+data.path+'"><img src="'+data.path+'" style="width:50px"/>';
										 li += '<input type="hidden" name="list[]" id="" value="'+data.path+'" />';
										 li += '<a href="javascript:;" class="delImg" style="color:red">X</a></li>';
			                            $("#photo-list").prepend(li);
			                        }
			                    });
			                });
			             </script>
					</td>
					<td id='photo-list'>
						
					</td>
				</tr>	
			</table>
			<!--异步删除图片-->
			<script type="text/javascript">
				$(function(){
					$(".delImg").live("click",function(){
						var url = $(this).parents("li").attr("url");
						var _this=$(this);
						$.ajax({
							type:"post",
							url:"<?php echo U('ajaxDelImg')?>",
							data:{url:url},
							dataType:"json",
							success:function(data){
								if(data == 1){
									_this.parents("li").remove();
								}
							}
						});
					})
				})
			</script>
			<p class="hd-title-header">商品图册</p>
			<table class='hd-table hd-table-form' style="border-top:1px solid #E5E5E5 ;">
			<tr class="info">
					<td>上传图片</td>
					<td>
						<input id="file2" type="file" multiple="true" name="photos"/>
	            		 <span>类型: *.jpg,*.png 大小: 2000KB 数量: 10</span>
			             <script type="text/javascript">
			                $(function() {
			                    $('#file2').uploadify({
			                        'formData'     : {//POST数据
			                            '<?php echo session_name();?>' : '<?php echo session_id();?>',
			                        },
			                        'fileTypeDesc' : '上传文件',//上传描述
			                        'fileTypeExts' : '*.jpg;*.png',
			                        'swf'      : 'Public/Admin/uploadify/uploadify.swf',
			                        'uploader' : "<?php echo U('ajaxUpload')?>",
			                        'buttonText':'选择文件',
			                        'fileSizeLimit' : '2000KB',
			                        'uploadLimit' : 1000,//上传文件数
			                        'width':65,
			                        'height':25,
			                        'successTimeout':10,//等待服务器响应时间
			                        'removeTimeout' : 0.2,//成功显示时间
			                        'onUploadSuccess' : function(file, data, response) {
			                            data=$.parseJSON(data);
			                            var imageUrl = data.image?data.url:'<?php echo __PUBLIC__?>/image/default.png';
										var li = '<li url="'+data.path+'"><img src="'+data.path+'" style="width:50px"/>';
										 li += '<input type="hidden" name="gpic[]" id="" value="'+data.path+'" />';
										 li += '<a href="javascript:;" class="delImg" style="color:red">X</a></li>';
			                            $("#photo-list1").prepend(li);
			                        }
			                    });
			                });
			             </script>
					</td>
					<td id='photo-list1'>
						
					</td>
				</tr>	
			</table>
			<!--异步删除图片-->
			<script type="text/javascript">
				$(function(){
					$(".delImg").live("click",function(){
						var url = $(this).parents("li").attr("url");
						var _this=$(this);
						$.ajax({
							type:"post",
							url:"<?php echo U('ajaxDelImg')?>",
							data:{url:url},
							dataType:"json",
							success:function(data){
								if(data == 1){
									_this.parents("li").remove();
								}
							}
						});
					})
				})
			</script>	
			</table>
			<p class="hd-title-header" id="detail">商品详细</p>
			<table class='hd-table hd-table-form'>
				<tr class="hide info">
					<td>
						<script id="ed" type="text/plain" style="width:100%;height:300px;" name="intro"></script>
	                    <script>
							var ue = UE.getEditor('ed');
						</script>
					</td>
				</tr>
			</table>
			<p class="hd-title-header" id="service">售后服务</p>
			<table class='table'>
				<tr class="hide info">
					<td>
						<!--<textarea name="service" id="service"></textarea>-->
						<script id="ed1" type="text/plain" style="width:100%;height:300px;" name="service"></script>
	                    <script>
							var ue = UE.getEditor('ed1');
						</script>
					</td>
				</tr>
			</table>
			<div id="tid">
				
			</div>
			
			<input type="submit" value="确认添加" class="hd-btn hd-btn-success" style="height: 40px;"/>
	</form>

	</div>
	</div>
	</div>
</body>
</html>